package model;

import java.util.HashMap;
import java.util.logging.Logger;

public class DataAccessor {	
	private static DataAccessor dataAccessor = null;
	private static Logger theLogger = Logger.getLogger("DataAccessor");
	
	public static String LOGIN = "login";
	public static String SAVEUSER = "saveuser"; 
	public static String DELETEUSER = "deleteuser";
	
	public static String VERIFYCLASSID = "varifyclassid"; // verifying the class number - it should be unique
	public static String VERIFYCLASSCODE = "varifyclasscode"; // verifying the class number - it should be unique
	public static String SAVECLASS = "saveclass"; 
	public static String DELETECLASS = "deleteclass"; 
	
	public static String SAVESTUDENT = "savestudent";  
	public static String SAVESTUDENTFEE = "savestudentfee";
	public static String DELETESTUDENT = "deletestudent";
	public static String DELETESTUDENTFEEDETAILS = "deletestudentfeedetails";
	public static String UPGRADESTUDENT = "upgradestudent"; 
	
	public static String SAVEQUICKLINK = "savequicklink";
	public static String VERIFYQUICKLINK = "verifyquicklink";
	public static String CONFIGUREYEAR = "configureyear";
	
	public static String SAVEEXPENSES = "saveexpenses";
	public static String DELETEEXPENSES = "deleteexpenses";
	
	public static void main(String[] args) {		
		String user = "gs";
		String password = "gs";	
		dataAccessor = DataAccessor.getInstance();
		dataAccessor.validateUser(user,password, "Student");
	}
	
	private DataAccessor() {
		theLogger.info("Logging\n");
	}
	
	public static synchronized DataAccessor getInstance() {
		if(dataAccessor == null)
			dataAccessor = new DataAccessor();
		return dataAccessor;
	}	
	
	/*
	 * This function is used to validate user. 
	 * It accepts user and password as parameters and returns a string.
	 */
	
	public synchronized String validateUser(String user, String password, String login_type) {
		Login login = new Login();
		return login.validateUser(user, password, login_type);
	}
	
	public synchronized HashMap<String, String> getStudentProgram(int student_id) {
		Login login = new Login();
		return login.getStudentProgram(student_id);
	}
	
	/**
	 * It will return the saved year.
	 * @return year
	 */
	public int getConfiguredYear() {
		Settings settings = Settings.getInstance();
		return settings.getConfiguredYear();
	}

	/*
	 * This function receives different parameters and calls the saveUser() method of User class to save these parameters.
	 */
	
	public synchronized String saveUser(int sessionUserId, int userId, String firstName, String lastName, String userName, String userPassword, int userLevel, int enabled, String phoneMobile, String emailAddress, String description) {
		User user = User.getInstance();
		return user.saveUser(sessionUserId, userId, firstName, lastName, userName, userPassword, userLevel, enabled, phoneMobile, emailAddress, description);	
	}  
	
	public synchronized void deleteUser(int userId) {
		User user = User.getInstance();
		user.deleteUser(userId);	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// FOR CLASS REALTED STUFF.
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public synchronized int verifyClassId(int classId) {
		ClassDetails classDetails = ClassDetails.getInstance();
		return classDetails.verifyClassId(classId);	
	}
	
	public synchronized int verifyClassCode(String classCode) {
		ClassDetails classDetails = ClassDetails.getInstance();
		return classDetails.verifyClassCode(classCode);	
	}
	
	/**
	 * 
	 * @param sessionUserId
	 * @param classId
	 * @param className
	 * @param classCode
	 * @param enabled
	 * @param classFee
	 * @param feeDue
	 * @param feePaid
	 * @param year
	 * @param description
	 */
	public synchronized void saveClass(int sessionUserId, int id, int classDetailId, int classId, String className, int enabled, double classFee, int year, int selectedYear, String description) {
		ClassDetails classDetails = ClassDetails.getInstance();
		classDetails.saveClass(sessionUserId, id, classDetailId, classId, className, enabled, classFee, year, selectedYear, description);	
	}  
	
	
	public synchronized void deleteClass(int classDetailId) {
		ClassDetails classDetails = ClassDetails.getInstance();
		classDetails.deleteClass(classDetailId);	
	}

	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// FOR STUDENT REALTED STUFF
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public synchronized void saveStudent(int sessionUserId, int studentFeeId, String rollNumber, int classDetailId, String name,
			String fatherName, String motherName, String address1,
			String address2, String mobile, String phone, double totalFee, String dob, String description) {
		
		StudentDetails studentDetails = StudentDetails.getInstance();
		studentDetails.saveStudent(sessionUserId, studentFeeId, rollNumber, classDetailId, name, fatherName, motherName, address1, address2, mobile, phone, totalFee, dob, description);
	}
	
	/**
	 * Method for saving the student fee
	 * @param sessionUserId
	 * @param studentFeeId
	 * @param recieptNumber
	 * @param feePay
	 * @param feeType
	 * @param feeRemark
	 */
	public synchronized void saveStudentFee(int sessionUserId, int studentFeeId, String recieptNumber, double feePay, String feeType, String feeRemark) {
		StudentDetails studentDetails = StudentDetails.getInstance();
		studentDetails.saveStudentFee(sessionUserId, studentFeeId, recieptNumber, feePay, feeType, feeRemark);
	}
	
	public synchronized void deleteStudent(int sessionUserId, int studentFeeId, String rollNumber) {
		StudentDetails studentDetails = StudentDetails.getInstance();
		studentDetails.deleteStudent(sessionUserId, studentFeeId, rollNumber);
	}
	
	public synchronized void deleteStudentFeeDetails(int sessionUserId, int studentFeeId, int feeId) {
		StudentDetails studentDetails = StudentDetails.getInstance();
		studentDetails.deleteStudentFeeDetails(sessionUserId, studentFeeId, feeId);
	}
	
	public synchronized String upgradeStudent(int sessionUserId, String rollNumber, int classDetailId, int year) {
		StudentDetails studentDetails = StudentDetails.getInstance();
		return studentDetails.upgradeStudent(sessionUserId, rollNumber, classDetailId, year);
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// FOR QUICK LINK REALTED STUFF
	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public synchronized void saveQickLink(int sessionUserId, int selectedYear, int quickLink1, int quickLink2, int quickLink3, int quickLink4, int quickLink5, int quickLink6) {
		Settings settings = Settings.getInstance();
		settings.saveQickLink(sessionUserId, selectedYear, quickLink1, quickLink2, quickLink3, quickLink4, quickLink5, quickLink6);
	}
	

	public synchronized String verifyQickLink(int sessionUserId, int selectedYear, int classId) {
		Settings settings = Settings.getInstance();
		return settings.verifyQickLink(sessionUserId, selectedYear, classId);
	}
	
	public synchronized void configureYear(int sessionUserId, int yearConfig) {
		Settings settings = Settings.getInstance();
		settings.configureYear(sessionUserId, yearConfig);
	}
	
	public synchronized String saveExpenses(int id, String paidTo, String dateAdded, String purpose, int lstUpdatedUser, double amount) {
		Expenses expenses = Expenses.getInstance();
		return expenses.saveExpenses(id, paidTo, dateAdded, purpose, lstUpdatedUser, amount);
	}
	
	public String deleteExpenses(int id) {
		Expenses expenses = Expenses.getInstance();
		return expenses.deleteExpenses(id);
	}
	
}